package com.captainbank.tcl.tclapplication.ui.activity.function;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.widget.TextView;
import android.widget.Toast;

import com.captainbank.tcl.tclapplication.R;
import com.captainbank.tcl.tclapplication.model.MarqueeEntity;
import com.captainbank.tcl.tclapplication.ui.activity.basic.BaseActivity;
import com.captainbank.tcl.tclapplication.utils.MyToast;
import com.sunfusheng.marqueeview.MarqueeView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by TCL on 2019/5/20.
 * Describe:
 *
 * 在 ListView 或 RecyclerView 的 Adapter 中
 * @Override
 * public void onViewDetachedFromWindow(@NonNull ViewHolder holder) {
 *     super.onViewDetachedFromWindow(holder);
 *     holder.marqueeView.stopFlipping();
 * }
 */
public class MarqueeActivity extends BaseActivity {
    @BindView(R.id.toolbar)
    Toolbar toolbar;
    @BindView(R.id.marqueeView1)
    MarqueeView marqueeView1;
    @BindView(R.id.marqueeView2)
    MarqueeView marqueeView2;
    @BindView(R.id.marqueeView3)
    MarqueeView marqueeView3;
    @BindView(R.id.marqueeView4)
    MarqueeView marqueeView4;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_marquee;
    }

    @Override
    protected void initData() {
        super.initData();
    }

    @Override
    protected void initView() {
        toolbar.setTitle(getString(R.string.title_marquee));

        //显示长文本
        String msg1 = "曾经沧海难为水，除却巫山不是云。取次花丛懒回顾，半缘修道半缘君";
        marqueeView1.startWithText(msg1);

        //String List
        List<String> msgList2 = new ArrayList<>();
        msgList2.add("1、帝高阳之苗裔兮，朕皇考曰伯庸。");
        msgList2.add("2、摄提贞于孟陬兮，惟庚寅吾以降。");
        msgList2.add("3、皇览揆余初度兮，肇锡余以嘉名。");
        msgList2.add("4、名余曰正则兮，字余曰灵均。");
        msgList2.add("5、纷吾既有此内美兮，又重之以修能。");
        msgList2.add("6、扈江离与辟芷兮，纫秋兰以为佩。");
        msgList2.add("7、汩余若将不及兮，恐年岁之不吾与。");
        marqueeView2.startWithList(msgList2);

        //自定义model list
        List<MarqueeEntity> msgList3 = new ArrayList<>();
        msgList3.add(new MarqueeEntity(1,"朝搴阰之木兰兮，夕揽洲之宿莽。"));
        msgList3.add(new MarqueeEntity(2,"日月忽其不淹兮，春与秋其代序。"));
        msgList3.add(new MarqueeEntity(3,"惟草木之零落兮，恐美人之迟暮。"));
        msgList3.add(new MarqueeEntity(4,"不抚壮而弃秽兮，何不改乎此度？"));
        msgList3.add(new MarqueeEntity(5,"乘骐骥以驰骋兮，来吾道夫先路！"));
        msgList3.add(new MarqueeEntity(6,"昔三后之纯粹兮，固众芳之所在。"));
        msgList3.add(new MarqueeEntity(7,"杂申椒与菌桂兮，岂惟纫夫蕙茝！"));
        marqueeView3.startWithList(msgList3);
    }

    @Override
    protected void setListener() {
        //String List
        List<String> msgList4 = new ArrayList<>();
        msgList4.add("彼尧、舜之耿介兮，既遵道而得路。");
        msgList4.add("何桀纣之昌披兮，夫惟捷径以窘步。");
        msgList4.add("惟夫党人之偷乐兮，路幽昧以险隘。");
        msgList4.add("岂余身之殚殃兮，恐皇舆之败绩。");
        msgList4.add("忽奔走以先后兮，及前王之踵武。");
        msgList4.add("荃不查余之中情兮，反信谗而齌怒。");
        msgList4.add("余固知謇謇之为患兮，忍而不能舍也。");
        marqueeView4.startWithList(msgList4);
        marqueeView4.setOnItemClickListener(new MarqueeView.OnItemClickListener() {
            @Override
            public void onItemClick(int position, TextView textView) {
                MyToast.toastSuccess(MarqueeActivity.this, "第"+position + "条:"+textView.getText().toString(),false);
            }
        });
    }

    @Override
    public void onStart() {
        super.onStart();
//        if (marqueeView1!=null){
//            marqueeView1.startFlipping();
//        }
//        if (marqueeView2!=null){
//            marqueeView2.startFlipping();
//        }
//        if (marqueeView3!=null){
//            marqueeView3.startFlipping();
//        }
//        if (marqueeView4!=null){
//            marqueeView4.startFlipping();
//        }

    }

    @Override
    public void onStop() {
        super.onStop();
//        if (marqueeView1!=null){
//            marqueeView1.stopFlipping();
//        }
//        if (marqueeView2!=null){
//            marqueeView2.stopFlipping();
//        }
//        if (marqueeView3!=null){
//            marqueeView3.stopFlipping();
//        }
//        if (marqueeView4!=null){
//            marqueeView4.stopFlipping();
//        }
    }

}
